//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

import { fetch } from '@tauri-apps/plugin-http';

export interface GitCodeOrg {
    id: number;
    login: string;
    path: string;
    name: string;
    url: string;
    description: string;
}

export async function list_org(accessToken: string): Promise<GitCodeOrg[]> {
    const headers = [["Origin", ""]] as [string, string][]; //fix http with unsafe-header return 403

    const res = await fetch(`https://api.gitcode.com/api/v5/users/orgs?access_token=${encodeURIComponent(accessToken)}&per_page=100`,
        {
            method: "GET",
            headers,
        });

    if (res.ok && res.status == 200) {
        return await res.json();
    } else {
        console.log(res);
        throw "error list org";
    }
}